package edu.whcp.comp2301.dao.impl;

import edu.whcp.comp2301.dao.DashboardDao;
import edu.whcp.comp2301.mapper.DashboardMapper;
import edu.whcp.comp2301.pojo.dto.NewsCountDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DashboardImpl implements DashboardDao {
    @Autowired
    private DashboardMapper dashboardMapper;

    @Override
    public Integer getNewsCount() {
        NewsCountDTO count = dashboardMapper.getNewsCount();
        return count.getCurrent_month_count();
    }

    @Override
    public Integer getNewsCountPercent() {
        NewsCountDTO count = dashboardMapper.getNewsCountPercent();
        return Math.round((count.getCurrent_month_count() - count.getLast_month_count()) / (float) count.getLast_month_count()) * 100;
    }

    @Override
    public Integer getUserCount() {
        NewsCountDTO count = dashboardMapper.getUserCount();
        return count.getCurrent_month_count();
    }

    @Override
    public Integer getUserCountPercent() {
        NewsCountDTO count = dashboardMapper.getUserCountPercent();
        return Math.round((count.getCurrent_month_count() - count.getLast_month_count()) / (float) count.getLast_month_count()) * 100;
    }

    @Override
    public Integer getCommentCount() {
        NewsCountDTO count = dashboardMapper.getCommentCount();
        return count.getCurrent_month_count();
    }

    @Override
    public Integer getCommentCountPercent() {
        NewsCountDTO count = dashboardMapper.getCommentCountPercent();
        return Math.round((count.getCurrent_month_count() - count.getLast_month_count()) / (float) count.getLast_month_count()) * 100;
    }
}
